{
	console.log("translate bar added...");
	d = document;
	b = d.body;
	o = d.createElement("scri" + "pt");
	o.setAttribute("src", "http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit");
	o.setAttribute("type", "text/javascript");
	b.appendChild(o);
	v = b.insertBefore(d.createElement("div"), b.firstChild);
	v.id = "google_translate_element";
	v.style.display = "none";
	p = d.createElement("scri" + "pt");
	p.text = 'function googleTranslateElementInit(){new google.translate.TranslateElement({pageLanguage:""},"google_translate_element");}';
	p.setAttribute("type", "text/javascript");
	b.appendChild(p);
	
	var intervalID1 = setInterval("saveSettings()",1000);
	var intervalID2 = (!skipSettings) ? setInterval("applySettings()",500) : null;
}

// true if bar has been seen at least once
var barSpotted = false;

function saveSettings(){
	try
	{
		if (barSpotted)
		{
			var sel = document.body.getElementsByClassName("goog-te-combo")[0];
			for (var i = 0; i < sel.length; i++)
			{
				if(sel[i].selected)
				{
					if (sel[i].value == "")
					{
						if (document.getElementById(":2.container").parentNode.style.display == "none")
						{
							clearInterval(intervalID1);
							console.log("bar closed & interval cleared");
							//do cleanup	//location.href cleanup too
						}
						else
						{
							//nothing happening
						}					
					}
					else
					{
						if (lang != sel[i].value)
						{
							chrome.extension.sendRequest({lang:sel[i].value},function(){});  //  <-- HERE
							lang = sel[i].value;
						}
					}
				}
			}
		}
		else if (document.getElementById(":2.container").parentNode.style.display == "")
		{
			console.log("bar spotted");
			barSpotted = true;
		}
	}
	catch(err)
	{
		
	}
}

function applySettings()
{
	console.log("trying to apply settings...", lang);
	try
	{
		if (lang == "undefined")
		{
			clearInterval(intervalID2);
			console.log("no applying settings");
			return;
		}
		var sel = document.body.getElementsByClassName("goog-te-combo")[0];
		if (/*sel.length < 53 &&*/ !barSpotted) return;
		var evObj = document.createEvent('MouseEvents');
		evObj.initEvent( 'change', true, true );
		for (var i = 0; i < sel.length; i++)
		{
			if (sel[i].value == lang)
				{
					sel[i].selected = 1;
					sel[i].dispatchEvent(evObj);
					console.log("applying lang:",sel[i],lang);  //  <-- HERE
				}
		}
		clearInterval(intervalID2);
	}
	catch(err)
	{
		console.log(err)
	}
}

void 0
